import axios from 'axios';
import query from 'query-string';

const BASE_URL = '/promotion/activity';


export interface ActivityParam {
    activityName?: string;
    page?: number;
    size?: number;
    sort?: Array<string>;
}

export interface ActivityResponse {
    id?: number;
    name: string;
    descs?: string;
    startTime?: string;
    endTime?: string;
    img?: string;
    status?: number;
    
    createdBy?: string;
    updatedBy?: string;
    createdAt?: string;
    updatedAt?: string;
}

export interface ActivitySaveCommand {
    id?: number;
    name: string;
    descs?: string;
    startTime?: string;
    endTime?: string;
    img?: string;
    status?: number;
}

export interface ActivityResponseList {
    list: ActivityResponse[];
    total: number;
}


// 通过ActivityParam参数获取分页列表
export function pageActivity(params: ActivityParam) {
    return axios.get<ActivityResponseList>(`${BASE_URL}/page`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    })
}

// 通过id获取活动信息
export function getActivity(id: number) {
    return axios.get<ActivityResponse>(`${BASE_URL}/${id}`);
    
}

export function listActivity(params: ActivityParam) {
    return axios.get<ActivityResponse[]>(`${BASE_URL}/list`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    });
}


// 添加活动
export function addActivity(params: ActivitySaveCommand) {
    return axios.post(`${BASE_URL}`, params);
}

// 更新活动
export function updateActivity(params: ActivitySaveCommand) {
    return axios.put(`${BASE_URL}`, params);
}

// 批量删除活动
export function deleteActivity(ids: number | Array<number>) {
    return axios.delete(`${BASE_URL}/${ids}`);
}